﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DTTB.Common;
using DTTB.Domain;

namespace DTTB.DAO
{
    public class PermissionsPerUsersDao : AccessData
    {
        //Lấy hết tất cả Permissions trong 'PermissionsPerUsers' của một user
        public IList<PermissionsPerUsers> GetPermissionsPerUserByUserId (string userId)
        {
            CommandText = "Select * From TB_PermissionsPerUsers P Where P.UserId = " + userId +
                          " and P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();
            IList<PermissionsPerUsers> list = CollectionHelper.ConvertTo<PermissionsPerUsers>(table);

            return list;
        }

        //Xóa tất cả Permissiions trong 'PermissionsPerUsers' của một User
        public bool DeleteAllPermissionPerUserByUserId(string userId)
        {
            CommandText = "Delete TB_PermissionsPerUsers Where UserId = " + userId;
            Commandtype = CommandType.Text;

            return Save();
        }

        //Lấy tất cả PermissionsPerUsers theo PathsId
        public IList<PermissionsPerUsers> GetPermissionsPerUserByPathId( string pathId)
        {
            CommandText = "Select * From TB_PermissionsPerUsers P Where P.PathId = " + pathId + " and P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();

            IList<PermissionsPerUsers> list = CollectionHelper.ConvertTo<PermissionsPerUsers>(table);
            return list;
        }

        public IList<PermissionsPerUsers> GetAllPermissionsPerUsers()
        {
            CommandText = "Select * From TB_PermissionsPerUsers P Where P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();
            IList<PermissionsPerUsers> list = CollectionHelper.ConvertTo<PermissionsPerUsers>(table);

            return list;
        }

        public bool AddNewPermissionsPerUsers(PermissionsPerUsers permissionsPerUsers)
        {
            return this.Insert("TB_PermissionsPerUsers", permissionsPerUsers);
        }
    }
}
